package com.zyx.sprintboot01cache.controller;

import com.zyx.sprintboot01cache.entity.Employee;
import com.zyx.sprintboot01cache.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: EmployeeController
 * @author: zyx
 * @E-mail: 1377631190@qq.com
 * @DATE: 2021/1/2 17:13
 */
@RestController
public class EmployeeController {

    @Autowired
    EmployeeService employeeService;

    @GetMapping("/emp/{id}")
    public Employee getEmployee(@PathVariable("id") Integer id) {
        Employee emp = employeeService.getEmp(id);
        return emp;
    }

    @PostMapping("/emp/update")
    public Employee update(Employee employee) {
        Employee update = employeeService.update(employee);
        return update;
    }

    @PostMapping("/emp/delete/{id}")
    public String delete(@PathVariable("id") Integer id) {
        employeeService.deleteEmp(id);
        return "success";
    }

}
